package com.zipking.cloud.springbootmybatis.util;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.zipking.cloud.springbootmybatis.persistance.entity.MsgLog;
import com.zipking.cloud.springbootmybatis.persistance.mapper.MsgLogMapper;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
@Slf4j
public class WorkThread<T> implements Callable<T> {

    /**
     * 需要处理的数据集合
     */
    private List<T> list;

    /**
     * 程序计数器
     */
    private CountDownLatch countDownLatch;

    /**
     * 线程名
     */
    private String threadName;

    public WorkThread (List list, String threadName, CountDownLatch countDownLatch){
        this.list=list;
        this.threadName=threadName;
        this.countDownLatch=countDownLatch;
    }

    @Override
    public T call() throws Exception {
       /* for (Object msgLog:list){
             log.info("当前数据:{}",JSON.toJSONString(msgLog));
        }*/
        MsgLogMapper msgLogMapper = SpringUtils.getBean(MsgLogMapper.class);
        Integer updateCount = msgLogMapper.updateBatchByIds((List<MsgLog>) list);
        log.info("updateCount:{}",updateCount);
        countDownLatch.countDown();
        return (T) updateCount;
    }


}

